package a04_字符串;

/**
 * <p>
 * a05_右旋字符串复习4
 * </p>
 *
 * @author flyduck
 * @since 2025/1/10
 */
public class a05_右旋字符串复习4 {
    public static String rightSwap(String str, int n) {
        char[] chars = str.toCharArray();
        reverse(chars,0,chars.length - 1);
        reverse(chars,0,n - 1);
        reverse(chars,n,chars.length - 1);
        return new String(chars);

    }

    public static void reverse(char[] chars,int leftIdx,int rightIdx){
        while (leftIdx < rightIdx) {
            char temp = chars[leftIdx];
            chars[leftIdx] = chars[rightIdx];
            chars[rightIdx] = temp;
            leftIdx++;
            rightIdx--;
        }
    }
}
